/****************************************************************************/
/*	File:		M4ViEncAPI.h												*/
/*	Author:		Marc Legrand			       								*/
/*	email:		marc.legrand@philips.com									*/
/*	Org:		Philips Digital Networks - MP4Net							*/
/*	Created:	03/04/2000	           										*/
/*	Purpose:	Definitions and structures for MPEG-4 Video encoder API		*/
/*	Notes:		MPEG-4 video encoder API specifications 1.0					*/
/*	Status:		Under development		           							*/
/*	Modified:																*/
/*																			*/
/*	Copyright (C) 	Royal Philips Electronics								*/
/*					2000. All rights reserved								*/
/*									   										*/
/****************************************************************************/

#ifndef M4VIENC_ENC_H
#define M4VIENC_ENC_H

#include "M4ViComAPI.h"

#ifdef __cplusplus
extern "C" {
#endif

/*################################
	Enumerated type definitions
#################################*/
enum M4V_VopType{
	M4V_I_VOP = 0,
	M4V_P_VOP,
	M4V_B_VOP
};
typedef enum M4V_VopType M4V_VOP_TYPE;

enum M4V_QuantMode{
	M4V_H263_METHOD = 0,
	M4V_MPEG2_METHOD
};
typedef enum M4V_QuantMode M4V_QUANT_MODE;

enum M4V_MotEstMode{
	M4V_MOTION_EST_3DRS = 0,
	M4V_MOTION_EST_FS,
	M4V_MOTION_EST_HW,
	M4V_MOTION_EST_MSEA
}	;
typedef enum M4V_MotEstMode M4V_MOT_EST_MODE;

enum M4V_MotEstRef{
	M4V_MOTION_EST_RECONSTRUCTED = 0,
	M4V_MOTION_EST_ORIGINAL
}	;
typedef enum M4V_MotEstRef M4V_MOT_EST_REFERENCE;

enum M4V_MotEstTools{
	M4V_MOTION_EST_TOOLS_ALL = 0,
	M4V_MOTION_EST_TOOLS_NO_4MV,
	M4V_MOTION_EST_TOOLS_NO_HALFPEL,
	M4V_MOTION_EST_TOOLS_NO_4MV_HALFPEL,
	M4V_MOTION_EST_TOOLS_NO_UMV,
	M4V_MOTION_EST_TOOLS_NO_UMV_4MV,
	M4V_MOTION_EST_TOOLS_NO_UMV_HALPEL,
	M4V_MOTION_EST_TOOLS_NO_UMV_4MV_HALPEL,
	M4V_MOTION_EST_TOOLS_NO_ESTMOT
}	;
typedef enum M4V_MotEstTools M4V_MOT_EST_TOOLS;

enum M4V_TSMode{
	M4V_TEMP_SCALABILITY_DISABLE = 0,
	M4V_TEMP_SCALABILITY_ENABLE
}	;
typedef enum M4V_TSMode M4V_TS_MODE;

enum M4V_RCMode{
	M4V_RATE_CONTROL_DISABLE = 0,
	M4V_RATE_CONTROL_ENABLE
}	;
typedef enum M4V_RCMode M4V_RATE_CONTROL_MODE;

enum M4V_ERMode{
	M4V_ERROR_RESILIENCE_DISABLE = 0,
	M4V_VIDEO_PACKETS_ENABLE,
	M4V_DATA_PARTITIONING_ENABLE
}	;
typedef enum M4V_ERMode M4V_ERROR_RESILIENCE_MODE;

enum M4V_FilmMode{
	M4V_FILM_MODE_DISABLE = 0,
	M4V_FILM_MODE_ENABLE
}	;
typedef enum M4V_FilmMode M4V_FILM_MODE;

enum M4V_Robustness{
	M4V_ROB_STREAM = 0,
	M4V_ROB_GOV,
	M4V_ROB_VOP,
	M4V_ROB_PACKET
}	;
typedef enum M4V_Robustness M4V_ROBUSTNESS;

enum M4V_Standard{
	M4V_MPEG4,
	M4V_H263
}	;
typedef enum M4V_Standard M4V_STANDARD_MODE;

enum M4V_OutputMode{
	M4V_NO_FRAME_OUTPUT,
	M4V_RECONSTRUCTED_ONLY,
	M4V_ORIG_REC
};

typedef enum M4V_OutputMode M4V_OUTPUT_REC_MODE;

enum M4V_CallBackState{
	M4V_CLOSE,
	M4V_OPEN
}	;
typedef enum M4V_CallBackState M4V_CALLBACK_STATE;

enum M4V_AcPrediction{
	M4V_AC_PREDICTION_DISABLE = 0,
	M4V_AC_PREDICTION_ENABLE
}	;
typedef enum M4V_AcPrediction M4V_AC_PREDICTION;

/*################################
		Error constants
#################################*/

#define M4V_ERRORBASE						4000

#define M4V_END_OF_CAPTURE					(M4V_ERRORBASE + 4)
#define M4V_INVALID_FUNCTION_CALL			(M4V_ERRORBASE + 5)
#define M4V_ILLEGAL_INPUT_FRAME_TYPE		(M4V_ERRORBASE + 6)
#define M4V_ILLEGAL_FRAME_WIDTH				(M4V_ERRORBASE + 7)
#define M4V_ILLEGAL_FRAME_HEIGHT			(M4V_ERRORBASE + 8)
#define M4V_ILLEGAL_FRAME_RATE				(M4V_ERRORBASE + 9)
#define M4V_ILLEGAL_SHAPE_MODE				(M4V_ERRORBASE + 10)
#define M4V_ILLEGAL_MOT_REFERENCE			(M4V_ERRORBASE + 11)
#define M4V_ILLEGAL_MOT_EST_TYPE			(M4V_ERRORBASE + 12)
#define M4V_ILLEGAL_H_SEARCH_RANGE			(M4V_ERRORBASE + 13)
#define M4V_ILLEGAL_V_SEARCH_RANGE			(M4V_ERRORBASE + 14)
#define M4V_ILLEGAL_QUANT_TYPE				(M4V_ERRORBASE + 15)
#define M4V_ILLEGAL_GOV_PERIOD				(M4V_ERRORBASE + 16)
#define M4V_ILLEGAL_OUTPUT_FRAME_TYPE		(M4V_ERRORBASE + 17)
#define M4V_ILLEGAL_SCALABILTY_TYPE			(M4V_ERRORBASE + 18)
#define M4V_ILLEGAL_DOWNSIZE_FACTOR			(M4V_ERRORBASE + 19)
#define M4V_ILLEGAL_DOWNSCALE_FACTOR		(M4V_ERRORBASE + 20)
#define M4V_ILLEGAL_BIT_RATE				(M4V_ERRORBASE + 21)
#define M4V_ILLEGAL_FRAME_RATE_RATIO		(M4V_ERRORBASE + 22)
#define M4V_ILLEGAL_I_PERIOD				(M4V_ERRORBASE + 23)
#define M4V_ILLEGAL_P_PERIOD				(M4V_ERRORBASE + 24)
#define M4V_ILLEGAL_SHAPE_PERIOD			(M4V_ERRORBASE + 25)
#define M4V_ILLEGAL_MQF_MODE				(M4V_ERRORBASE + 26)
#define M4V_ILLEGAL_INIT_I_QUANT			(M4V_ERRORBASE + 27)
#define M4V_ILLEGAL_INIT_P_QUANT			(M4V_ERRORBASE + 28)
#define M4V_ILLEGAL_INIT_B_QUANT			(M4V_ERRORBASE + 29)
#define M4V_ILLEGAL_ER_MODE					(M4V_ERRORBASE + 30)
#define M4V_ILLEGAL_PACKET_SIZE				(M4V_ERRORBASE + 31)
#define M4V_ILLEGAL_LAYER_NB				(M4V_ERRORBASE + 32)
#define M4V_ILLEGAL_CAPTURE_RATE_NUM		(M4V_ERRORBASE + 33)
#define M4V_ILLEGAL_CAPTURE_RATE_DENUM		(M4V_ERRORBASE + 34)
#define M4V_ILLEGAL_RATE_CONTROL			(M4V_ERRORBASE + 35)
#define M4V_ILLEGAL_BUFFER_TIME_WINDOW		(M4V_ERRORBASE + 36)
#define M4V_ILLEGAL_MOTIONQUALITY_FACTOR	(M4V_ERRORBASE + 37)
#define M4V_ILLEGAL_BUFFER_SIZE				(M4V_ERRORBASE + 38)
#define M4V_ILLEGAL_ASPECT_RATIO			(M4V_ERRORBASE + 39)
#define M4V_ILLEGAL_RATE_FACTOR				(M4V_ERRORBASE + 40)
#define M4V_ILLEGAL_PROFILE_LEVEL			(M4V_ERRORBASE + 41)
#define M4V_ILLEGAL_STANDARD_MODE			(M4V_ERRORBASE + 42)

/*###################################
		Data type declarations
####################################*/

/************************************************/
/*		input parameters						*/
/************************************************/
typedef	struct
{
 M4V_COLOUR_FORMAT 		FrameType;
 M4ViComU16				FrameWidth;
 M4ViComU16				FrameHeight;
 M4ViComU32 			CaptureRateNumerator;
 M4ViComU32 			CaptureRateDenominator;
} M4ViEncInputParameterEncoder;


/************************************************/
/*		Video Object parameters					*/
/************************************************/
typedef	struct
{
  M4V_STANDARD_MODE 	StandardMode;
  M4V_SHAPE_MODE 		ShapeMode;
  M4V_TS_MODE 			TemporalScalability;
  M4V_FILM_MODE			FilmDetectionMode;
  M4V_MOT_EST_MODE 		MotionEstimationType;
  M4V_MOT_EST_REFERENCE MotionEstimationReference;
  M4V_MOT_EST_TOOLS     MotionEstimationTools;
  M4ViComU32			HorizontalSearchRange;
  M4ViComU32			VerticalSearchRange;
  M4V_QUANT_MODE 		QuantizationType;
  M4ViComU32			GOVperiod;
  M4ViComU32 			PSNRLevel;
  M4ViComU32 			DownsizeFactor;
  M4ViComU8				RenderingOutputFrameMode;
  M4ViComFloat 			RenderingRate;
  M4V_COLOUR_FORMAT 	OutputFrameType;
  M4V_AC_PREDICTION     AcPrediction;

} M4ViEncVoParameterEncoder;


/************************************************/
/*		Video Object layer parameters			*/
/************************************************/
typedef struct
{
  M4ViComU32 				BitRate;
  M4ViComU32 				FrameRateRatio;
  M4ViComU32 				IVopPeriod;
  M4ViComU32 				PVopPeriod;
  M4ViComU32 				IShapePeriod;
  M4ViComU8					MotionQualityFactorEnable;
  M4ViComU8					MotionQualityFactor;
  M4V_RATE_CONTROL_MODE		RateControlEnable;
  M4ViComU32				DefaultIQuantizer;
  M4ViComU32 				DefaultPQuantizer;
  M4ViComU32 				DefaultBQuantizer;
  M4V_ERROR_RESILIENCE_MODE	ErrorResilienceMode;
  M4ViComU32 				VideoPacketSize;
  M4ViComU32 				BufferSize;
  M4ViComU32 				BufferTimeWindow;
  M4ViComPARinfo			AspectRatio;
  M4ViComU8					RateFactor;
} M4ViEncVolParameterEncoder;


/************************************************/
/*		Encoder Properties						*/
/************************************************/
typedef	struct
{
  M4ViComU32 		MaxFragmentSize;
  M4ViComU32 		MaxVOSSize;
  M4ViComU32 		MaxVOSize;
  M4ViComU32 		MaxVOLSize;
  M4ViComU32 		MaxGOVSize;
  M4ViComU32 		MaxEOSSize;
  M4ViComU32 		MaxVideoPacketNumber;
  M4ViComU32 		NumberOfLayer;
} M4ViEncEncoderProperties;


/************************************************/
/*		 Vop information						*/
/************************************************/
typedef struct
{
  M4V_LAYER_TYPE	layer_nb;
  M4V_VOP_TYPE 		VopType;
  M4ViComDouble		cts;
  M4ViComDouble		dts;
  M4ViComU32		byte_length;
  M4ViComU32 		QuantizationStep;
  M4ViComFloat 		BufferOccupancy;
  M4ViComU32 		RawFrameEncoded;
  M4ViComU32 		VopEncoded;
} M4ViEncVopInfo;


/************************************************/
/*		 Visual Header structure				*/
/************************************************/
typedef struct
{
  M4ViComU32		byte_length;
  M4ViComU8			*pi8_buffer;
} M4ViEncVisualHeader;


typedef struct {
	void *context;
	M4ViComU8	flag;
} M4ViEncInFilterData;

/************************************************/
/*		 Video fragment							*/
/************************************************/
typedef	struct
{
  M4V_LAYER_TYPE	layer_nb;
  M4ViComU32		index;
  M4ViComU32		robustness;
  M4ViComU32		byte_length;
  M4ViComU32		partition_one_bit_length;
  M4ViComU8			*pi8_buffer;
} M4ViEncVideoFragment;

/************************************************/
/* call-back functions prototypes definition	*/
/************************************************/
/* typedef M4ViComErrorCode (p_M4ViEncProcessVideoFragment)(M4ViComHandleInstance , M4V_CALLBACK_STATE, void *,M4ViEncVideoFragment **); */
/* typedef M4ViComErrorCode (p_M4ViEncProcessVideoFrame)(M4ViComHandleInstance , M4V_CALLBACK_STATE, void *, M4ViComDouble cts,M4ViComImagePlane **,M4ViComImagePlane **); */
/* typedef M4ViComErrorCode (p_M4ViEncProcessAccessUnit)(M4ViComHandleInstance , M4V_CALLBACK_STATE, void *, M4ViComDouble cts, M4ViComDouble dts, M4ViEncVopInfo	**); */
/* typedef M4ViComErrorCode (p_FilterInputVideoFrame)(M4ViComImagePlane *PlaneIn, M4ViComImagePlane *PlaneOut); */

typedef M4ViComErrorCode (*p_M4ViEncProcessAccessUnit)(M4ViComHandleInstance Hinstance, M4V_CALLBACK_STATE state, void* handler, M4ViComDouble cts, M4ViComDouble dts, M4ViEncVopInfo **VopInfo); /* process AU method */
typedef M4ViComErrorCode (*p_M4ViEncProcessVideoFragment)(M4ViComHandleInstance Hinstance, M4V_CALLBACK_STATE state, void* handler, M4ViEncVideoFragment **VideoFragment);	/* process fragment method */
typedef M4ViComErrorCode (*p_M4ViEncProcessVideoFrame)(M4ViComHandleInstance Hinstance, M4V_CALLBACK_STATE state, void* handler, M4ViComDouble cts, M4ViComImagePlane **RecVideoFrame, M4ViComImagePlane **OriVideoFrame);	/* process frame method */
typedef M4ViComErrorCode (*p_M4FilterInputVideoFrame)(void *user_data, M4ViComImagePlane *PlaneIn, M4ViComImagePlane *PlaneOut);	/* pre-process input frame method */

/************************************************/
/*		Function declarations					*/
/************************************************/

M4ViComErrorCode	M4ViEncInitEncoderLibrary(
M4V_CPU_TYPE cpu_type,
void** library_data);

M4ViComErrorCode	M4ViEncFreeEncoderLibrary(void* library_data);

M4ViComErrorCode	M4ViEncGetEncoderDevicesVersion(M4ViComVersion * VersionInfo);

M4ViComErrorCode	M4ViEncGetDefaultVisualObjectParameters (
M4ViEncVoParameterEncoder       *SequenceParams);

M4ViComErrorCode	M4ViEncGetDefaultVideoObjectLayerParameters (
M4ViEncVolParameterEncoder* VolParams);

M4ViComErrorCode	M4ViEncGetEncoderInstance (
M4ViComHandleInstance           *Hinstance,
void* library_data);

M4ViComErrorCode	M4ViEncSetInputParameters (
M4ViComHandleInstance           Hinstance,
M4ViEncInputParameterEncoder    InputParams,
void* library_data);

M4ViComErrorCode	M4ViEncSetVoParameters (
M4ViComHandleInstance           Hinstance,
M4ViEncVoParameterEncoder       SequenceParams,
void* library_data);

M4ViComErrorCode	M4ViEncSetVolParameters (
M4ViComHandleInstance           Hinstance,
M4ViComU8                       Layer,
M4ViEncVolParameterEncoder      VolParams,
void* library_data);

M4ViComErrorCode	M4ViEncGiveBitratePerfInfo(M4ViComHandleInstance Hinstance,
M4ViComU8 Layer,
M4ViComU32 Target_Bitrate,
M4ViComU32 Mean_Bitrate,
void* library_data);

M4ViComErrorCode	M4ViEncCreateEncoder (
M4ViComHandleInstance           Hinstance,
M4ViEncEncoderProperties        *EncoderProperties,
void* library_data);

M4ViComErrorCode	M4ViEncGetVisualObjectSequenceHeader(
M4ViComHandleInstance   Hinstance,
M4ViEncVisualHeader     *VisualObjectSequenceHeader,
void* library_data);

M4ViComErrorCode	M4ViEncGetVisualObjectHeader (
M4ViComHandleInstance   Hinstance,
M4ViEncVisualHeader     *VisualObjectHeader,
void* library_data);

M4ViComErrorCode	M4ViEncGetVideoObjectLayerHeader (
M4ViComHandleInstance   Hinstance,
M4ViComU8               Layer,
M4ViEncVisualHeader     *VisualObjectLayerHeader,
void* library_data);

M4ViComErrorCode	M4ViEncProcessFrame (
M4ViComHandleInstance   Hinstance,
M4ViComImagePlane       *InputFrame,
M4ViComDouble           cts,
M4ViComBoolean          last_frame_flag,
void* library_data);

M4ViComErrorCode	M4ViEncStopEncoder(
M4ViComHandleInstance   Hinstance,
M4ViEncVisualHeader     *visual_object_sequence_end_code,
void* library_data);

M4ViComErrorCode	M4ViEncDestroyEncoder (
M4ViComHandleInstance *Hinstance,
void* library_data);

M4ViComErrorCode	M4ViEncSetMPEG4StreamMethods(
M4ViComHandleInstance          Hinstance,
void*                          handler,
p_M4ViEncProcessAccessUnit     ProcessAccessUnitMethod,
p_M4ViEncProcessVideoFragment  ProcessVideoFragmentMethod,
void* library_data);

M4ViComErrorCode	M4ViEncSetVideoFrameMethod(
M4ViComHandleInstance          Hinstance,
void*                          handler,
void*                          in_f_handler,
p_M4ViEncProcessVideoFrame     ProcessVideoFrameMethod,
p_M4FilterInputVideoFrame        FilterInputVideoFrameMethod,
p_M4VOutputFilter              FilterOutputVideoFrameMethod,
void* library_data);

M4ViComErrorCode	M4ViEncSetQuantStep(M4ViComHandleInstance Hinstance, M4ViComU8 Layer, M4ViComU8 Qp, void* library_data);
M4ViComErrorCode	M4ViEncSetPrefiltering(M4ViComHandleInstance Hinstance, M4ViComU8 u8_prefiltering, void* library_data);

M4ViComErrorCode M4ViEncSetNextFrameAsI(M4ViComHandleInstance Hinstance, void* library_data);

#ifdef __cplusplus
}
#endif

#endif /* M4VIENC_ENC_H */

